# coding: utf-8


class SyntaxTreeNode(object):
    TAB = "=-"
    production = None
    parent = None
    parts = None
    local_symbol_table = None
    variable_type = None
    line = None

    def __init__(self, production, parts, line=None):
        self.production = production
        self.parent = None
        self.parts = parts
        self.variable_type = None
        self.line = line

    def __repr__(self):
        return "Node({0})".format(self.production, self.parts)

    def as_strings(self, tabs=0):
        nodes_str = ""
        for el in self.parts:
            if type(el) == SyntaxTreeNode:
                nodes_str += el.as_strings(tabs+1)
            else:
                nodes_str += "{0}{1}, {2}\n".format(SyntaxTreeNode.TAB * (tabs + 1), el, el.variable_type)

        return "{0}{1} ({2}), {3}, {4}\n{5}".format(SyntaxTreeNode.TAB * tabs,
                                              self.production,
                                              self.line,
                                              self.variable_type,
                                              str(self.local_symbol_table),
                                              nodes_str)

    def get_type(self):
        return self.production